package com.xiaoma.eventpublish;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;


@Component
public class BusinessPublisher implements ApplicationEventPublisherAware {

    //spring提供的事件发布组件
    private ApplicationEventPublisher applicationEventPublisher;
    /**
     * 发布事件
     */
    public void publishEvent(BusinessEvent businessEvent) {
        System.out.println("发布事件:" + businessEvent.getType());
        this.applicationEventPublisher.publishEvent(businessEvent);
    }


    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }


}
